if (!("finalizeConstruction" in ViewPU.prototype)) {
    Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { });
}
import customScan from "@hms.core.scan.customScan";
import scanCore from "@hms.core.scan.scanCore";
import { requestPermissionsFromUser } from '../../Utils/scannerUtils/PermissionUtil';
import picker from "@ohos.file.picker";
import { ScanUtil } from '../../Utils/scannerUtils/ScanUtil';
import { ResultState } from '../../Utils/scannerUtils/ResultState';
import image from "@ohos.multimedia.image";
import { calculateLuminance } from '../../Utils/scannerUtils/ImageUtil';
export class ProScanner extends ViewPU {
    constructor(b5, c5, d5, e5 = -1, f5 = undefined, g5) {
        super(b5, d5, e5, g5);
        if (typeof f5 === "function") {
            this.paramsGenerator_ = f5;
        }
        this.__albumsShow = new SynchedPropertySimpleOneWayPU(c5.albumsShow, this, "albumsShow");
        this.__albumsIcon = new SynchedPropertyObjectOneWayPU(c5.albumsIcon, this, "albumsIcon");
        this.__albumsIconSize = new SynchedPropertyObjectOneWayPU(c5.albumsIconSize, this, "albumsIconSize");
        this.__albumsText = new SynchedPropertySimpleOneWayPU(c5.albumsText, this, "albumsText");
        this.__albumsTextSize = new SynchedPropertyObjectOneWayPU(c5.albumsTextSize, this, "albumsTextSize");
        this.__albumsTextColor = new SynchedPropertyObjectOneWayPU(c5.albumsTextColor, this, "albumsTextColor");
        this.__lightShow = new SynchedPropertySimpleOneWayPU(c5.lightShow, this, "lightShow");
        this.__lightCloseIcon = new SynchedPropertyObjectOneWayPU(c5.lightCloseIcon, this, "lightCloseIcon");
        this.__lightOpenIcon = new SynchedPropertyObjectOneWayPU(c5.lightOpenIcon, this, "lightOpenIcon");
        this.__lightIconSize = new SynchedPropertyObjectOneWayPU(c5.lightIconSize, this, "lightIconSize");
        this.__lightOpenText = new SynchedPropertySimpleOneWayPU(c5.lightOpenText, this, "lightOpenText");
        this.__lightCloseText = new SynchedPropertySimpleOneWayPU(c5.lightCloseText, this, "lightCloseText");
        this.__lightTextSize = new SynchedPropertyObjectOneWayPU(c5.lightTextSize, this, "lightTextSize");
        this.__lightTextColor = new SynchedPropertyObjectOneWayPU(c5.lightTextColor, this, "lightTextColor");
        this.__scanIntervalTime = new SynchedPropertySimpleOneWayPU(c5.scanIntervalTime, this, "scanIntervalTime");
        this.__pointViewSize = new SynchedPropertySimpleOneWayPU(c5.pointViewSize, this, "pointViewSize");
        this.__pointViewColor = new SynchedPropertyObjectOneWayPU(c5.pointViewColor, this, "pointViewColor");
        this.__pointViewBorderWidth = new SynchedPropertySimpleOneWayPU(c5.pointViewBorderWidth, this, "pointViewBorderWidth");
        this.__pointIcon = new SynchedPropertyObjectOneWayPU(c5.pointIcon, this, "pointIcon");
        this.__pointIconSize = new SynchedPropertySimpleOneWayPU(c5.pointIconSize, this, "pointIconSize");
        this.__pointViewBorderColor = new SynchedPropertyObjectOneWayPU(c5.pointViewBorderColor, this, "pointViewBorderColor");
        this.__pointViewLeftOffset = new SynchedPropertySimpleOneWayPU(c5.pointViewLeftOffset, this, "pointViewLeftOffset");
        this.__pointViewTopOffset = new SynchedPropertySimpleOneWayPU(c5.pointViewTopOffset, this, "pointViewTopOffset");
        this.__onceScan = new SynchedPropertySimpleOneWayPU(c5.onceScan, this, "onceScan");
        this.__scanTypes = new SynchedPropertyObjectOneWayPU(c5.scanTypes, this, "scanTypes");
        this.__safeAreaType = new SynchedPropertyObjectOneWayPU(c5.safeAreaType, this, "safeAreaType");
        this.__safeAreaEdge = new SynchedPropertyObjectOneWayPU(c5.safeAreaEdge, this, "safeAreaEdge");
        this.pointView = this.PointView;
        this.__luminanceAnalyzerInterval = new SynchedPropertySimpleOneWayPU(c5.luminanceAnalyzerInterval, this, "luminanceAnalyzerInterval");
        this.luminanceListener = undefined;
        this.controller = undefined;
        this.onFindMultipleCode = undefined;
        this.onScanResult = undefined;
        this.onCameraGrant = undefined;
        this.onCameraReject = undefined;
        this.mXComponentController = new XComponentController();
        this.surfaceId = undefined;
        this.viewControl = undefined;
        this.defaultWidth = 360;
        this.defaultHeight = 640;
        this.__screenWidth = new ObservedPropertySimplePU(this.defaultWidth, this, "screenWidth");
        this.__screenHeight = new ObservedPropertySimplePU(this.defaultHeight, this, "screenHeight");
        this.__isLoaded = new ObservedPropertySimplePU(false, this, "isLoaded");
        this.__isLightOpen = new ObservedPropertySimplePU(false, this, "isLightOpen");
        this.__points = new ObservedPropertyObjectPU([], this, "points");
        this.__firstShow = new ObservedPropertySimplePU(true, this, "firstShow");
        this.__isStop = new ObservedPropertySimplePU(false, this, "isStop");
        this.__isRelease = new ObservedPropertySimplePU(false, this, "isRelease");
        this.__isFirstScanSuccess = new ObservedPropertySimplePU(false, this, "isFirstScanSuccess");
        this.scanConsumed = true;
        this.luminanceAnalyzerId = 0;
        this.callback = async (h5, i5) => {
            this.scanConsumed = true;
            if (this.isRelease) {
                return;
            }
            if (h5) {
                console.warn(`扫描错误, code: ${h5.code}, message: ${h5.message}`);
                if (h5.code != 1000500001) {
                    this.onScanResult?.(ResultState.Fail, h5.message);
                }
                if (!this.isRelease) {
                    this.rescan();
                }
                return;
            }
            console.log(`扫描成功, result: ${JSON.stringify(i5)}`);
            if (i5) {
                if (i5.length <= 1) {
                    if (this.onceScan) {
                        if (!this.isFirstScanSuccess) {
                            this.points = [];
                            this.onScanResult?.(ResultState.Success, i5[0].originalValue);
                        }
                        this.isFirstScanSuccess = true;
                    }
                    else {
                        this.points = [];
                        this.onScanResult?.(ResultState.Success, i5[0].originalValue);
                    }
                    if (!this.isRelease) {
                        this.rescan();
                    }
                }
                else {
                    if (this.onceScan) {
                        if (!this.isFirstScanSuccess) {
                            this.points = i5;
                            this.onFindMultipleCode?.(i5);
                            this.closeLight();
                            this.isStop = true;
                            try {
                                customScan.stop();
                            }
                            catch (k5) {
                                console.warn(k5);
                            }
                        }
                        this.isFirstScanSuccess = true;
                    }
                    else {
                        this.points = i5;
                        this.onFindMultipleCode?.(i5);
                        this.closeLight();
                        this.isStop = true;
                        try {
                            customScan.stop();
                        }
                        catch (j5) {
                            console.warn(j5);
                        }
                    }
                }
            }
            else {
                this.points = [];
                this.onScanResult?.(ResultState.Fail, '未找到二维码');
                if (!this.isRelease) {
                    this.rescan();
                }
            }
        };
        this.setInitiallyProvidedValue(c5);
        this.declareWatch("isLoaded", this.startScan);
        this.finalizeConstruction();
    }
    setInitiallyProvidedValue(a5) {
        if (a5.albumsShow === undefined) {
            this.__albumsShow.set(true);
        }
        if (a5.albumsIcon === undefined) {
            this.__albumsIcon.set({ "id": -1, "type": 20000, params: ['app.media.scanner_albums'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" });
        }
        if (a5.albumsIconSize === undefined) {
            this.__albumsIconSize.set(64);
        }
        if (a5.albumsText === undefined) {
            this.__albumsText.set('相册');
        }
        if (a5.albumsTextSize === undefined) {
            this.__albumsTextSize.set(16);
        }
        if (a5.albumsTextColor === undefined) {
            this.__albumsTextColor.set(Color.White);
        }
        if (a5.lightShow === undefined) {
            this.__lightShow.set(true);
        }
        if (a5.lightCloseIcon === undefined) {
            this.__lightCloseIcon.set({ "id": -1, "type": 20000, params: ['app.media.scanner_light_close'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" });
        }
        if (a5.lightOpenIcon === undefined) {
            this.__lightOpenIcon.set({ "id": -1, "type": 20000, params: ['app.media.scanner_light_open'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" });
        }
        if (a5.lightIconSize === undefined) {
            this.__lightIconSize.set(64);
        }
        if (a5.lightOpenText === undefined) {
            this.__lightOpenText.set('开灯');
        }
        if (a5.lightCloseText === undefined) {
            this.__lightCloseText.set('关灯');
        }
        if (a5.lightTextSize === undefined) {
            this.__lightTextSize.set(16);
        }
        if (a5.lightTextColor === undefined) {
            this.__lightTextColor.set(Color.White);
        }
        if (a5.scanIntervalTime === undefined) {
            this.__scanIntervalTime.set(1000);
        }
        if (a5.pointViewSize === undefined) {
            this.__pointViewSize.set(40);
        }
        if (a5.pointViewColor === undefined) {
            this.__pointViewColor.set('#4AA4F9');
        }
        if (a5.pointViewBorderWidth === undefined) {
            this.__pointViewBorderWidth.set(3);
        }
        if (a5.pointIcon === undefined) {
            this.__pointIcon.set({ "id": -1, "type": 20000, params: ['app.media.scanner_arrow_right'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" });
        }
        if (a5.pointIconSize === undefined) {
            this.__pointIconSize.set(26);
        }
        if (a5.pointViewBorderColor === undefined) {
            this.__pointViewBorderColor.set(Color.White);
        }
        if (a5.pointViewLeftOffset === undefined) {
            this.__pointViewLeftOffset.set(20);
        }
        if (a5.pointViewTopOffset === undefined) {
            this.__pointViewTopOffset.set(20);
        }
        if (a5.onceScan === undefined) {
            this.__onceScan.set(false);
        }
        if (a5.scanTypes === undefined) {
            this.__scanTypes.set([scanCore.ScanType.ALL]);
        }
        if (a5.safeAreaType === undefined) {
            this.__safeAreaType.set([SafeAreaType.SYSTEM]);
        }
        if (a5.safeAreaEdge === undefined) {
            this.__safeAreaEdge.set([SafeAreaEdge.BOTTOM]);
        }
        if (a5.pointView !== undefined) {
            this.pointView = a5.pointView;
        }
        if (a5.luminanceAnalyzerInterval === undefined) {
            this.__luminanceAnalyzerInterval.set(1000);
        }
        if (a5.luminanceListener !== undefined) {
            this.luminanceListener = a5.luminanceListener;
        }
        if (a5.controller !== undefined) {
            this.controller = a5.controller;
        }
        if (a5.onFindMultipleCode !== undefined) {
            this.onFindMultipleCode = a5.onFindMultipleCode;
        }
        if (a5.onScanResult !== undefined) {
            this.onScanResult = a5.onScanResult;
        }
        if (a5.onCameraGrant !== undefined) {
            this.onCameraGrant = a5.onCameraGrant;
        }
        if (a5.onCameraReject !== undefined) {
            this.onCameraReject = a5.onCameraReject;
        }
        if (a5.mXComponentController !== undefined) {
            this.mXComponentController = a5.mXComponentController;
        }
        if (a5.surfaceId !== undefined) {
            this.surfaceId = a5.surfaceId;
        }
        if (a5.viewControl !== undefined) {
            this.viewControl = a5.viewControl;
        }
        if (a5.defaultWidth !== undefined) {
            this.defaultWidth = a5.defaultWidth;
        }
        if (a5.defaultHeight !== undefined) {
            this.defaultHeight = a5.defaultHeight;
        }
        if (a5.screenWidth !== undefined) {
            this.screenWidth = a5.screenWidth;
        }
        if (a5.screenHeight !== undefined) {
            this.screenHeight = a5.screenHeight;
        }
        if (a5.isLoaded !== undefined) {
            this.isLoaded = a5.isLoaded;
        }
        if (a5.isLightOpen !== undefined) {
            this.isLightOpen = a5.isLightOpen;
        }
        if (a5.points !== undefined) {
            this.points = a5.points;
        }
        if (a5.firstShow !== undefined) {
            this.firstShow = a5.firstShow;
        }
        if (a5.isStop !== undefined) {
            this.isStop = a5.isStop;
        }
        if (a5.isRelease !== undefined) {
            this.isRelease = a5.isRelease;
        }
        if (a5.isFirstScanSuccess !== undefined) {
            this.isFirstScanSuccess = a5.isFirstScanSuccess;
        }
        if (a5.scanConsumed !== undefined) {
            this.scanConsumed = a5.scanConsumed;
        }
        if (a5.luminanceAnalyzerId !== undefined) {
            this.luminanceAnalyzerId = a5.luminanceAnalyzerId;
        }
        if (a5.callback !== undefined) {
            this.callback = a5.callback;
        }
    }
    updateStateVars(z4) {
        this.__albumsShow.reset(z4.albumsShow);
        this.__albumsIcon.reset(z4.albumsIcon);
        this.__albumsIconSize.reset(z4.albumsIconSize);
        this.__albumsText.reset(z4.albumsText);
        this.__albumsTextSize.reset(z4.albumsTextSize);
        this.__albumsTextColor.reset(z4.albumsTextColor);
        this.__lightShow.reset(z4.lightShow);
        this.__lightCloseIcon.reset(z4.lightCloseIcon);
        this.__lightOpenIcon.reset(z4.lightOpenIcon);
        this.__lightIconSize.reset(z4.lightIconSize);
        this.__lightOpenText.reset(z4.lightOpenText);
        this.__lightCloseText.reset(z4.lightCloseText);
        this.__lightTextSize.reset(z4.lightTextSize);
        this.__lightTextColor.reset(z4.lightTextColor);
        this.__scanIntervalTime.reset(z4.scanIntervalTime);
        this.__pointViewSize.reset(z4.pointViewSize);
        this.__pointViewColor.reset(z4.pointViewColor);
        this.__pointViewBorderWidth.reset(z4.pointViewBorderWidth);
        this.__pointIcon.reset(z4.pointIcon);
        this.__pointIconSize.reset(z4.pointIconSize);
        this.__pointViewBorderColor.reset(z4.pointViewBorderColor);
        this.__pointViewLeftOffset.reset(z4.pointViewLeftOffset);
        this.__pointViewTopOffset.reset(z4.pointViewTopOffset);
        this.__onceScan.reset(z4.onceScan);
        this.__scanTypes.reset(z4.scanTypes);
        this.__safeAreaType.reset(z4.safeAreaType);
        this.__safeAreaEdge.reset(z4.safeAreaEdge);
        this.__luminanceAnalyzerInterval.reset(z4.luminanceAnalyzerInterval);
    }
    purgeVariableDependenciesOnElmtId(y4) {
        this.__albumsShow.purgeDependencyOnElmtId(y4);
        this.__albumsIcon.purgeDependencyOnElmtId(y4);
        this.__albumsIconSize.purgeDependencyOnElmtId(y4);
        this.__albumsText.purgeDependencyOnElmtId(y4);
        this.__albumsTextSize.purgeDependencyOnElmtId(y4);
        this.__albumsTextColor.purgeDependencyOnElmtId(y4);
        this.__lightShow.purgeDependencyOnElmtId(y4);
        this.__lightCloseIcon.purgeDependencyOnElmtId(y4);
        this.__lightOpenIcon.purgeDependencyOnElmtId(y4);
        this.__lightIconSize.purgeDependencyOnElmtId(y4);
        this.__lightOpenText.purgeDependencyOnElmtId(y4);
        this.__lightCloseText.purgeDependencyOnElmtId(y4);
        this.__lightTextSize.purgeDependencyOnElmtId(y4);
        this.__lightTextColor.purgeDependencyOnElmtId(y4);
        this.__scanIntervalTime.purgeDependencyOnElmtId(y4);
        this.__pointViewSize.purgeDependencyOnElmtId(y4);
        this.__pointViewColor.purgeDependencyOnElmtId(y4);
        this.__pointViewBorderWidth.purgeDependencyOnElmtId(y4);
        this.__pointIcon.purgeDependencyOnElmtId(y4);
        this.__pointIconSize.purgeDependencyOnElmtId(y4);
        this.__pointViewBorderColor.purgeDependencyOnElmtId(y4);
        this.__pointViewLeftOffset.purgeDependencyOnElmtId(y4);
        this.__pointViewTopOffset.purgeDependencyOnElmtId(y4);
        this.__onceScan.purgeDependencyOnElmtId(y4);
        this.__scanTypes.purgeDependencyOnElmtId(y4);
        this.__safeAreaType.purgeDependencyOnElmtId(y4);
        this.__safeAreaEdge.purgeDependencyOnElmtId(y4);
        this.__luminanceAnalyzerInterval.purgeDependencyOnElmtId(y4);
        this.__screenWidth.purgeDependencyOnElmtId(y4);
        this.__screenHeight.purgeDependencyOnElmtId(y4);
        this.__isLoaded.purgeDependencyOnElmtId(y4);
        this.__isLightOpen.purgeDependencyOnElmtId(y4);
        this.__points.purgeDependencyOnElmtId(y4);
        this.__firstShow.purgeDependencyOnElmtId(y4);
        this.__isStop.purgeDependencyOnElmtId(y4);
        this.__isRelease.purgeDependencyOnElmtId(y4);
        this.__isFirstScanSuccess.purgeDependencyOnElmtId(y4);
    }
    aboutToBeDeleted() {
        this.__albumsShow.aboutToBeDeleted();
        this.__albumsIcon.aboutToBeDeleted();
        this.__albumsIconSize.aboutToBeDeleted();
        this.__albumsText.aboutToBeDeleted();
        this.__albumsTextSize.aboutToBeDeleted();
        this.__albumsTextColor.aboutToBeDeleted();
        this.__lightShow.aboutToBeDeleted();
        this.__lightCloseIcon.aboutToBeDeleted();
        this.__lightOpenIcon.aboutToBeDeleted();
        this.__lightIconSize.aboutToBeDeleted();
        this.__lightOpenText.aboutToBeDeleted();
        this.__lightCloseText.aboutToBeDeleted();
        this.__lightTextSize.aboutToBeDeleted();
        this.__lightTextColor.aboutToBeDeleted();
        this.__scanIntervalTime.aboutToBeDeleted();
        this.__pointViewSize.aboutToBeDeleted();
        this.__pointViewColor.aboutToBeDeleted();
        this.__pointViewBorderWidth.aboutToBeDeleted();
        this.__pointIcon.aboutToBeDeleted();
        this.__pointIconSize.aboutToBeDeleted();
        this.__pointViewBorderColor.aboutToBeDeleted();
        this.__pointViewLeftOffset.aboutToBeDeleted();
        this.__pointViewTopOffset.aboutToBeDeleted();
        this.__onceScan.aboutToBeDeleted();
        this.__scanTypes.aboutToBeDeleted();
        this.__safeAreaType.aboutToBeDeleted();
        this.__safeAreaEdge.aboutToBeDeleted();
        this.__luminanceAnalyzerInterval.aboutToBeDeleted();
        this.__screenWidth.aboutToBeDeleted();
        this.__screenHeight.aboutToBeDeleted();
        this.__isLoaded.aboutToBeDeleted();
        this.__isLightOpen.aboutToBeDeleted();
        this.__points.aboutToBeDeleted();
        this.__firstShow.aboutToBeDeleted();
        this.__isStop.aboutToBeDeleted();
        this.__isRelease.aboutToBeDeleted();
        this.__isFirstScanSuccess.aboutToBeDeleted();
        SubscriberManager.Get().delete(this.id__());
        this.aboutToBeDeletedInternal();
    }
    get albumsShow() {
        return this.__albumsShow.get();
    }
    set albumsShow(x4) {
        this.__albumsShow.set(x4);
    }
    get albumsIcon() {
        return this.__albumsIcon.get();
    }
    set albumsIcon(w4) {
        this.__albumsIcon.set(w4);
    }
    get albumsIconSize() {
        return this.__albumsIconSize.get();
    }
    set albumsIconSize(v4) {
        this.__albumsIconSize.set(v4);
    }
    get albumsText() {
        return this.__albumsText.get();
    }
    set albumsText(u4) {
        this.__albumsText.set(u4);
    }
    get albumsTextSize() {
        return this.__albumsTextSize.get();
    }
    set albumsTextSize(t4) {
        this.__albumsTextSize.set(t4);
    }
    get albumsTextColor() {
        return this.__albumsTextColor.get();
    }
    set albumsTextColor(s4) {
        this.__albumsTextColor.set(s4);
    }
    get lightShow() {
        return this.__lightShow.get();
    }
    set lightShow(r4) {
        this.__lightShow.set(r4);
    }
    get lightCloseIcon() {
        return this.__lightCloseIcon.get();
    }
    set lightCloseIcon(q4) {
        this.__lightCloseIcon.set(q4);
    }
    get lightOpenIcon() {
        return this.__lightOpenIcon.get();
    }
    set lightOpenIcon(p4) {
        this.__lightOpenIcon.set(p4);
    }
    get lightIconSize() {
        return this.__lightIconSize.get();
    }
    set lightIconSize(o4) {
        this.__lightIconSize.set(o4);
    }
    get lightOpenText() {
        return this.__lightOpenText.get();
    }
    set lightOpenText(n4) {
        this.__lightOpenText.set(n4);
    }
    get lightCloseText() {
        return this.__lightCloseText.get();
    }
    set lightCloseText(m4) {
        this.__lightCloseText.set(m4);
    }
    get lightTextSize() {
        return this.__lightTextSize.get();
    }
    set lightTextSize(l4) {
        this.__lightTextSize.set(l4);
    }
    get lightTextColor() {
        return this.__lightTextColor.get();
    }
    set lightTextColor(k4) {
        this.__lightTextColor.set(k4);
    }
    get scanIntervalTime() {
        return this.__scanIntervalTime.get();
    }
    set scanIntervalTime(j4) {
        this.__scanIntervalTime.set(j4);
    }
    get pointViewSize() {
        return this.__pointViewSize.get();
    }
    set pointViewSize(i4) {
        this.__pointViewSize.set(i4);
    }
    get pointViewColor() {
        return this.__pointViewColor.get();
    }
    set pointViewColor(h4) {
        this.__pointViewColor.set(h4);
    }
    get pointViewBorderWidth() {
        return this.__pointViewBorderWidth.get();
    }
    set pointViewBorderWidth(g4) {
        this.__pointViewBorderWidth.set(g4);
    }
    get pointIcon() {
        return this.__pointIcon.get();
    }
    set pointIcon(f4) {
        this.__pointIcon.set(f4);
    }
    get pointIconSize() {
        return this.__pointIconSize.get();
    }
    set pointIconSize(e4) {
        this.__pointIconSize.set(e4);
    }
    get pointViewBorderColor() {
        return this.__pointViewBorderColor.get();
    }
    set pointViewBorderColor(d4) {
        this.__pointViewBorderColor.set(d4);
    }
    get pointViewLeftOffset() {
        return this.__pointViewLeftOffset.get();
    }
    set pointViewLeftOffset(c4) {
        this.__pointViewLeftOffset.set(c4);
    }
    get pointViewTopOffset() {
        return this.__pointViewTopOffset.get();
    }
    set pointViewTopOffset(b4) {
        this.__pointViewTopOffset.set(b4);
    }
    get onceScan() {
        return this.__onceScan.get();
    }
    set onceScan(a4) {
        this.__onceScan.set(a4);
    }
    get scanTypes() {
        return this.__scanTypes.get();
    }
    set scanTypes(z3) {
        this.__scanTypes.set(z3);
    }
    get safeAreaType() {
        return this.__safeAreaType.get();
    }
    set safeAreaType(y3) {
        this.__safeAreaType.set(y3);
    }
    get safeAreaEdge() {
        return this.__safeAreaEdge.get();
    }
    set safeAreaEdge(x3) {
        this.__safeAreaEdge.set(x3);
    }
    get luminanceAnalyzerInterval() {
        return this.__luminanceAnalyzerInterval.get();
    }
    set luminanceAnalyzerInterval(w3) {
        this.__luminanceAnalyzerInterval.set(w3);
    }
    get screenWidth() {
        return this.__screenWidth.get();
    }
    set screenWidth(v3) {
        this.__screenWidth.set(v3);
    }
    get screenHeight() {
        return this.__screenHeight.get();
    }
    set screenHeight(u3) {
        this.__screenHeight.set(u3);
    }
    get isLoaded() {
        return this.__isLoaded.get();
    }
    set isLoaded(t3) {
        this.__isLoaded.set(t3);
    }
    get isLightOpen() {
        return this.__isLightOpen.get();
    }
    set isLightOpen(s3) {
        this.__isLightOpen.set(s3);
    }
    get points() {
        return this.__points.get();
    }
    set points(r3) {
        this.__points.set(r3);
    }
    get firstShow() {
        return this.__firstShow.get();
    }
    set firstShow(q3) {
        this.__firstShow.set(q3);
    }
    get isStop() {
        return this.__isStop.get();
    }
    set isStop(p3) {
        this.__isStop.set(p3);
    }
    get isRelease() {
        return this.__isRelease.get();
    }
    set isRelease(o3) {
        this.__isRelease.set(o3);
    }
    get isFirstScanSuccess() {
        return this.__isFirstScanSuccess.get();
    }
    set isFirstScanSuccess(n3) {
        this.__isFirstScanSuccess.set(n3);
    }
    aboutToAppear() {
        this.controller?.init(this);
    }
    aboutToDisappear() {
        this.releaseScan();
    }
    pickPhoto() {
        let k3 = new picker.PhotoSelectOptions();
        k3.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
        k3.maxSelectNumber = 1;
        let l3 = new picker.PhotoViewPicker();
        l3.select(k3).then((m3) => {
            this.scanUri(m3.photoUris[0]);
        });
    }
    openLight() {
        if (this.isLoaded && !this.isLightOpen && !this.isStop) {
            try {
                customScan.openFlashLight();
            }
            catch (j3) {
                console.warn(j3);
            }
            this.isLightOpen = true;
        }
    }
    closeLight() {
        if (this.isLoaded && this.isLightOpen && !this.isStop) {
            try {
                customScan.closeFlashLight();
            }
            catch (i3) {
                console.warn(i3);
            }
            this.isLightOpen = false;
        }
    }
    toggleLight() {
        if (this.isLoaded && !this.isStop) {
            try {
                if (this.isLightOpen) {
                    customScan.closeFlashLight();
                }
                else {
                    customScan.openFlashLight();
                }
            }
            catch (h3) {
                console.warn(h3);
            }
            this.isLightOpen = !this.isLightOpen;
        }
    }
    setZoom(f3) {
        try {
            customScan.setZoom(f3);
        }
        catch (g3) {
            console.warn(g3);
        }
    }
    getZoom() {
        try {
            return customScan.getZoom();
        }
        catch (e3) {
            console.warn(e3);
            return 0;
        }
    }
    getLightStatus() {
        try {
            return customScan.getFlashLightStatus();
        }
        catch (d3) {
            console.warn(d3);
            return false;
        }
    }
    startScan() {
        if (this.isLoaded) {
            if (this.viewControl != undefined) {
                this.checkPermissionAndInitCamera();
            }
        }
        else {
            this.releaseScan();
        }
    }
    scanUrl(a3, b3 = {
        scanTypes: this.scanTypes,
        enableMultiMode: true,
        enableAlbum: true
    }) {
        const c3 = ScanUtil.scanUrl(getContext(this), a3, b3);
        this.scanPromiseHandler(c3);
    }
    scanPixelMap(x2, y2 = {
        scanTypes: this.scanTypes,
        enableMultiMode: true,
        enableAlbum: true
    }) {
        const z2 = ScanUtil.scanPixelMap(getContext(this), x2, y2);
        this.scanPromiseHandler(z2);
    }
    scanUri(u2, v2 = {
        scanTypes: this.scanTypes,
        enableMultiMode: true,
        enableAlbum: true
    }) {
        const w2 = ScanUtil.scanUri(u2, v2);
        this.scanPromiseHandler(w2);
    }
    scanPromiseHandler(r2) {
        r2.then((t2) => {
            this.onScanResult?.(ResultState.Success, t2);
        }).catch((s2) => {
            this.onScanResult?.(ResultState.Fail, s2);
        });
    }
    rescan(p2 = this.scanIntervalTime) {
        try {
            setTimeout(() => {
                if (!this.isRelease) {
                    customScan.stop().then(() => {
                        customScan.start(this.viewControl, this.callback);
                    }).catch(() => {
                        customScan.start(this.viewControl, this.callback);
                    });
                    this.isRelease = false;
                    this.isStop = false;
                }
            }, p2);
        }
        catch (q2) {
            console.warn(q2);
        }
    }
    checkPermissionAndInitCamera() {
        requestPermissionsFromUser(getContext(this), 'ohos.permission.CAMERA')
            .then(() => {
            this.onCameraGrant?.();
            if (canIUse('SystemCapability.Multimedia.Scan.Core')) {
                let n2 = {
                    scanTypes: this.scanTypes,
                    enableMultiMode: true,
                    enableAlbum: true
                };
                try {
                    if (this.scanConsumed) {
                        customScan.init(n2);
                        customScan.start(this.viewControl, this.callback);
                        this.points = [];
                        this.scanConsumed = false;
                        this.isRelease = false;
                    }
                }
                catch (o2) {
                    console.warn(o2);
                }
            }
            else {
                console.warn('不支持扫码');
                return;
            }
        }).catch(() => {
            this.onCameraReject?.();
            console.warn('初始化相机异常');
        });
    }
    releaseScan() {
        this.isRelease = true;
        this.scanConsumed = true;
        try {
            if (canIUse('SystemCapability.Multimedia.Scan.Core')) {
                customScan.stop().then(() => {
                    console.log('相机停止成功');
                }).catch((m2) => {
                });
                customScan.release().then(() => {
                    console.log('相机释放成功');
                }).catch((l2) => {
                });
            }
            else {
                console.warn('不支持扫码');
                return;
            }
        }
        catch (k2) {
            console.warn(k2);
        }
    }
    startAnalyzer() {
        if (!this.luminanceAnalyzerId) {
            this.luminanceAnalyzerId = setInterval(() => {
                image.createPixelMapFromSurface(this.surfaceId, { x: 0, y: 0, size: { height: this.defaultHeight, width: this.defaultHeight } }).then((i2) => {
                    calculateLuminance(i2).then((j2) => {
                        this.luminanceListener?.(j2);
                    });
                });
            }, this.luminanceAnalyzerInterval);
        }
    }
    initialRender() {
        this.observeComponentCreation2((c2, d2) => {
            Stack.create();
            Stack.backgroundColor(Color.Black);
            Stack.onSizeChange((g2, h2) => {
                this.screenWidth = h2.width;
                this.screenHeight = h2.height;
            });
            Stack.onVisibleAreaChange([0.0, 1.0], (e2, f2) => {
                if (e2 && (f2 >= 1.0 || (f2 > 0.9 && this.safeAreaType &&
                    this.safeAreaType?.length > 0 && this.safeAreaEdge && this.safeAreaEdge.length > 0))) {
                    if (!this.firstShow) {
                        this.startScan();
                    }
                    this.firstShow = false;
                    if (this.luminanceListener) {
                        this.startAnalyzer();
                    }
                }
                if (!e2 && f2 <= 0) {
                    this.releaseScan();
                    if (this.luminanceAnalyzerId) {
                        clearInterval(this.luminanceAnalyzerId);
                        this.luminanceAnalyzerId = 0;
                    }
                }
            });
            Stack.expandSafeArea(ObservedObject.GetRawObject(this.safeAreaType), ObservedObject.GetRawObject(this.safeAreaEdge));
        }, Stack);
        this.Camera.bind(this)();
        this.MarkPoint.bind(this)();
        this.ButtonLayout.bind(this)();
        Stack.pop();
    }
    ButtonLayout(h1 = null) {
        this.observeComponentCreation2((a2, b2) => {
            Column.create();
            Column.height('100%');
            Column.width('100%');
            Column.justifyContent(FlexAlign.End);
            Column.hitTestBehavior(HitTestMode.Transparent);
        }, Column);
        this.observeComponentCreation2((y1, z1) => {
            Row.create();
            Row.margin({ bottom: 20 });
        }, Row);
        this.observeComponentCreation2((w1, x1) => {
            Column.create();
            Column.visibility(this.albumsShow ? Visibility.Visible : Visibility.None);
            Column.onClick(() => {
                this.pickPhoto();
            });
        }, Column);
        this.observeComponentCreation2((u1, v1) => {
            Image.create(this.albumsIcon);
            Image.height(ObservedObject.GetRawObject(this.albumsIconSize));
            Image.width(ObservedObject.GetRawObject(this.albumsIconSize));
        }, Image);
        this.observeComponentCreation2((s1, t1) => {
            Text.create(this.albumsText);
            Text.fontSize(ObservedObject.GetRawObject(this.albumsTextSize));
            Text.fontColor(ObservedObject.GetRawObject(this.albumsTextColor));
            Text.margin({ top: 4, bottom: 10 });
        }, Text);
        Text.pop();
        Column.pop();
        this.observeComponentCreation2((o1, p1) => {
            If.create();
            if (this.albumsShow && this.lightShow) {
                this.ifElseBranchUpdateFunction(0, () => {
                    this.observeComponentCreation2((q1, r1) => {
                        Divider.create();
                        Divider.vertical(true);
                        Divider.strokeWidth(10);
                        Divider.color(Color.Transparent);
                        Divider.width(81);
                        Divider.height(ObservedObject.GetRawObject(this.albumsIconSize));
                    }, Divider);
                });
            }
            else {
                this.ifElseBranchUpdateFunction(1, () => {
                });
            }
        }, If);
        If.pop();
        this.observeComponentCreation2((m1, n1) => {
            Column.create();
            Column.visibility(this.lightShow ? Visibility.Visible : Visibility.None);
            Column.onClick(() => {
                this.toggleLight();
            });
        }, Column);
        this.observeComponentCreation2((k1, l1) => {
            Image.create(this.isLightOpen ? this.lightOpenIcon : this.lightCloseIcon);
            Image.height(ObservedObject.GetRawObject(this.lightIconSize));
            Image.width(ObservedObject.GetRawObject(this.lightIconSize));
        }, Image);
        this.observeComponentCreation2((i1, j1) => {
            Text.create(this.isLightOpen ? this.lightOpenText : this.lightCloseText);
            Text.fontSize(ObservedObject.GetRawObject(this.lightTextSize));
            Text.fontColor(ObservedObject.GetRawObject(this.lightTextColor));
            Text.margin({ top: 4, bottom: 10 });
        }, Text);
        Text.pop();
        Column.pop();
        Row.pop();
        Column.pop();
    }
    MarkPoint(v = null) {
        this.observeComponentCreation2((f1, g1) => {
            Stack.create();
            Stack.height('100%');
            Stack.width('100%');
            Stack.hitTestBehavior(HitTestMode.Transparent);
        }, Stack);
        this.observeComponentCreation2((w, x) => {
            ForEach.create();
            const y = z => {
                const a1 = z;
                this.observeComponentCreation2((b1, c1) => {
                    If.create();
                    if (this.pointView && a1.scanCodeRect) {
                        this.ifElseBranchUpdateFunction(0, () => {
                            this.observeComponentCreation2((d1, e1) => {
                                Row.create();
                                Row.position({
                                    left: this.switchLeft(a1) + (this.switchRight(a1) - this.switchLeft(a1)) / 2 - this.pointViewLeftOffset,
                                    top: this.switchTop(a1) + (this.switchBottom(a1) - this.switchTop(a1)) / 2 - this.pointViewTopOffset,
                                    right: this.switchLeft(a1) + (this.switchRight(a1) - this.switchLeft(a1)) / 2 - this.pointViewLeftOffset,
                                    bottom: this.switchTop(a1) + (this.switchBottom(a1) - this.switchTop(a1)) / 2 - this.pointViewTopOffset
                                });
                                Row.onClick(() => {
                                    this.onScanResult?.(ResultState.Success, a1.originalValue);
                                    this.points = [];
                                    this.rescan(0);
                                });
                            }, Row);
                            this.pointView.bind(this)();
                            Row.pop();
                        });
                    }
                    else {
                        this.ifElseBranchUpdateFunction(1, () => {
                        });
                    }
                }, If);
                If.pop();
            };
            this.forEachUpdateFunction(w, this.points, y);
        }, ForEach);
        ForEach.pop();
        Stack.pop();
    }
    switchLeft(u) {
        if (u.scanCodeRect) {
            return (u.scanCodeRect.left / this.defaultWidth) * this.screenWidth;
        }
        else {
            return 0;
        }
    }
    switchRight(t) {
        if (t.scanCodeRect) {
            return (t.scanCodeRect.right / this.defaultWidth) * this.screenWidth;
        }
        else {
            return 0;
        }
    }
    switchTop(s) {
        if (s.scanCodeRect) {
            return (s.scanCodeRect.top / this.defaultHeight) * this.screenHeight;
        }
        else {
            return 0;
        }
    }
    switchBottom(r) {
        if (r.scanCodeRect) {
            return (r.scanCodeRect.bottom / this.defaultHeight) * this.screenHeight;
        }
        else {
            return 0;
        }
    }
    PointView(k = null) {
        this.observeComponentCreation2((p, q) => {
            Row.create();
            Row.justifyContent(FlexAlign.Center);
            Row.width(this.pointViewSize);
            Row.height(this.pointViewSize);
            Row.borderRadius(this.pointViewSize / 2);
            Row.borderWidth(this.pointViewBorderWidth);
            Row.borderColor(ObservedObject.GetRawObject(this.pointViewBorderColor));
        }, Row);
        this.observeComponentCreation2((n, o) => {
            Row.create();
            Row.alignItems(VerticalAlign.Center);
            Row.justifyContent(FlexAlign.Center);
            Row.width('100%');
            Row.height('100%');
            Row.borderRadius('50%');
            Row.backgroundColor(ObservedObject.GetRawObject(this.pointViewColor));
        }, Row);
        this.observeComponentCreation2((l, m) => {
            Image.create(this.pointIcon);
            Image.width(this.pointIconSize);
            Image.height(this.pointIconSize);
        }, Image);
        Row.pop();
        Row.pop();
    }
    Camera(f = null) {
        this.observeComponentCreation2((g, h) => {
            XComponent.create({
                id: 'componentId',
                type: XComponentType.SURFACE,
                controller: this.mXComponentController
            }, "com.coner.ScanDemo/Scanner");
            XComponent.onLoad(() => {
                this.surfaceId = this.mXComponentController.getXComponentSurfaceId();
                this.viewControl = {
                    width: this.screenWidth,
                    height: this.screenHeight,
                    surfaceId: this.surfaceId
                };
                this.isLoaded = true;
                this.startScan();
            });
            XComponent.backgroundColor(Color.Transparent);
            XComponent.width(this.screenWidth);
            XComponent.height(this.screenHeight);
            XComponent.position({ x: 0, y: 0 });
            Gesture.create(GesturePriority.Low);
            PinchGesture.create();
            PinchGesture.onActionUpdate((i) => {
                if (this.isLoaded) {
                    try {
                        customScan.setZoom(customScan.getZoom() * i.scale);
                    }
                    catch (j) {
                        console.warn(j);
                    }
                }
            });
            PinchGesture.pop();
            Gesture.pop();
        }, XComponent);
    }
    rerender() {
        this.updateDirtyElements();
    }
}
export class ProScannerController {
    init(e) {
        this.scanner = e;
    }
    openLight() {
        this.scanner?.openLight();
    }
    closeLight() {
        this.scanner?.closeLight();
    }
    toggleLight() {
        this.scanner?.toggleLight();
    }
    pickPhoto() {
        this.scanner?.pickPhoto();
    }
    setZoom(d) {
        this.scanner?.setZoom(d);
    }
    getZoom() {
        return this.scanner?.getZoom() ?? 0;
    }
    getLightStatus() {
        return this.scanner?.getLightStatus() ?? false;
    }
    releaseScan() {
        this.scanner?.releaseScan();
    }
    startScan() {
        this.scanner?.startScan();
    }
    rescan() {
        this.scanner?.rescan();
    }
    scanUri(c) {
        this.scanner?.scanUri(c);
    }
    scanUrl(b) {
        this.scanner?.scanUrl(b);
    }
    scanPixelMap(a) {
        this.scanner?.scanPixelMap(a);
    }
}
